def isPrime(d):
    if d == 1: return False
    t = True
    k = d - 1
    while k > 1:
        if not d % k:
            t = False
            break
        k -= 1
    return t

e = input ()
r =[]
for i in range(len(e)):
    for k in range(i + 1,len(e) +  1):
        d = int (e[i:k])
        if isPrime(d):
            r += [d]
print(max(r) if r else 0)
